#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import sys
import json


# ROOT PATH
EXE_DIR = os.path.dirname(sys.argv[0])
EXE_PATH = os.path.join(EXE_DIR, 'OpenXL.exe')
if os.path.exists(EXE_PATH):
    ROOT_DIR = EXE_DIR
else:
    ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# CONFIG PATH
CONFIG_DIR = os.path.join(ROOT_DIR, 'Config')

# SCRIPTS PATH
SCRIPTS_DIR = os.path.join(ROOT_DIR, 'Scripts')

# SRC PATH
SRC_DIR = os.path.join(ROOT_DIR, 'Src')

# UTILS PATH
UTILS_DIR = os.path.join(ROOT_DIR, 'Utils')

# LOGS PATH
LOGS_DIR = os.path.join(ROOT_DIR, 'Logs')

# EXCEL FILE PATH
EXCEL_FILE_DIR = os.path.join(ROOT_DIR, 'ExcelFiles')
SCRIPT_EXCEL_DIR = os.path.join(EXCEL_FILE_DIR, 'ScriptExcel')
try:
    config_file_path = os.path.join(CONFIG_DIR, 'LocalMachineConfig.json')
    with open(config_file_path, 'r', encoding='utf-8') as r:
        config_dict = json.load(r)
    config_excel_path = config_dict['LocalConfigExcelsPath']
    if config_excel_path and os.path.exists(config_excel_path):
        CONFIG_EXCEL_DIR = config_excel_path
    else:
        CONFIG_EXCEL_DIR = os.path.join(EXCEL_FILE_DIR, 'ConfigExcel')
except Exception as e:
    print('读取ScriptExcelConfig.json文件失败')
    raise e


CONFIG_EXCEL_NAME_LIST = ['activity.xlsx', 'objects.xlsx', 'shop.xlsx', 'disgift.xlsx', 'giftbox.xlsx', 'drops.xlsx',
                          'sequence.xlsx', 'ShopConfig.xlsx', 'ActivityConfig.xlsx', 'PreviewConfig.xlsx',
                          'TimeShopConfig.xlsx']

if __name__ == '__main__':
    print(os.path.exists(ROOT_DIR))
    print(os.path.exists(EXCEL_FILE_DIR))
    print(os.path.exists(CONFIG_EXCEL_DIR))
    print(os.path.exists(SCRIPT_EXCEL_DIR))
    print(os.path.exists(SCRIPTS_DIR))
    print(os.path.exists(SRC_DIR))
    print(os.path.exists(UTILS_DIR))
    print(os.path.exists(LOGS_DIR))
